const loanTermList = [
  { label: "12期", value: 12 },
  { label: "24期", value: 24 },
  { label: "36期", value: 36 },
  { label: "48期", value: 48 },
  { label: "60期", value: 60 }
];

const bankList = [
  { label: "中国银行", value: 1 },
  { label: "中国工商银行", value: 2 },
  { label: "中国邮政银行", value: 3 },
  { label: "中国农业银行", value: 4 },
  { label: "中国建设银行", value: 5 }
];

const tabList = [
  { name: "基本信息", id: 0 },
  { name: "办理要求", id: 1 },
  // { name: "个人要求", id: 1 },
  // { name: "企业要求", id: 2 },
  // { name: "征信要求", id: 3 },
  { name: "准入地区", id: 2 },
  { name: "禁入行业", id: 3 },
  { name: "申请流程", id: 4 }
  // { name: "所需材料", id: 6 },
];
const pickerOptions = {
  disabledDate(time) {
    return time.getTime() > Date.now();
  },
  shortcuts: [
    {
      text: "今天",
      onClick(picker) {
        picker.$emit("pick", new Date());
      }
    },
    {
      text: "昨天",
      onClick(picker) {
        const date = new Date();
        date.setTime(date.getTime() - 3600 * 1000 * 24);
        picker.$emit("pick", date);
      }
    },
    {
      text: "一周前",
      onClick(picker) {
        const date = new Date();
        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
        picker.$emit("pick", date);
      }
    },
    {
      text: "一年前",
      onClick(picker) {
        const date = new Date();
        date.setFullYear(date.getFullYear() - 1);
        picker.$emit("pick", date);
      }
    },
    {
      text: "两年前",
      onClick(picker) {
        const date = new Date();
        date.setFullYear(date.getFullYear() - 2);
        picker.$emit("pick", date);
      }
    },
    {
      text: "三年前",
      onClick(picker) {
        const date = new Date();
        date.setFullYear(date.getFullYear() - 3);
        picker.$emit("pick", date);
      }
    }
  ]
};
var validatadvantage = (rule, value, callback) => {
  let valueArr = value.map(v => {
    return v.value;
  });
  if (valueArr.some(v => v !== "")) {
    callback();
  } else {
    callback(new Error("请填写至少一项产品优势"));
  }
};

var checkPriceSell = (rule, value, callback) => {
  if (value) {
    if (!/^\d+(\.\d{1,2})?$/.test(value)) {
      callback(new Error("请填写正确的值！"));
    } else {
      callback();
    }
  }
};

var checkPriceSellA = (rule, value, callback) => {
  if (value) {
    const regex = /^(?:[1-9]\d*|0)(?:\.\d{1,4})?$/;
    if (!regex.test(value)) {
      callback(new Error("请填写正确的值！"));
    } else {
      callback();
    }
  }
};

const rules = {
  pic: [{ required: true, message: "请上传产品图片", trigger: "change" }],
  name: [{ required: true, message: "请输入产品名称", trigger: "change" }],
  bankId: [{ required: true, message: "请选择所属银行", trigger: "change" }],
  minQuota: [
    { required: true, message: "请输入最小额度", trigger: "change" },
    { validator: checkPriceSell, trigger: "change" }
  ],
  maxQuota: [
    { required: true, message: "请输入最大额度", trigger: "change" },
    { validator: checkPriceSell, trigger: "change" }
  ],
  minAnnualRate: [
    { required: true, message: "请输入最小年化利率", trigger: "change" },
    { validator: checkPriceSellA, trigger: "change" }
  ],
  maxAnnualRate: [
    { required: true, message: "请输入最大年化利率", trigger: "change" },
    { validator: checkPriceSellA, trigger: "change" }
  ],
  corporateAge: [
    { required: true, message: "请输入最小年龄", trigger: "change" }
  ],
  corporateMaxAge: [
    { required: true, message: "请输入最大年龄", trigger: "change" }
  ],
  loanTerm: [{ required: true, message: "请选择还款期限", trigger: "change" }],
  repaymentType: [
    { required: true, message: "请选择还款方式", trigger: "change" }
  ],
  advantageData: [
    { required: true, validator: validatadvantage, trigger: "change" }
  ],
  legalApplyRequire: [
    { required: true, message: "请输入法人申请条件", trigger: "change" }
  ],
  companyTaxInfo: [
    { required: true, message: "请输入企业纳税情况", trigger: "change" }
  ],

  companyBankFlow: [
    { required: true, message: "请输入企业流水要求", trigger: "change" }
  ],
  accessArea: [
    { required: true, message: "请输入准入地区", trigger: "change" }
  ],
  prohibitIndustry: [
    { required: true, message: "请输入禁止行业", trigger: "change" }
  ],
  matchType: [
    {
      required: true,
      message: "请选择匹配类型",
      trigger: "change"
    }
  ],
  accessAreaList: [
    {
      required: true,
      message: "请选择准入地区",
      trigger: "change"
    }
  ],
  title: [{ required: true, message: "请输入标题", trigger: "change" }],
  content: [{ required: true, message: "请输入内容", trigger: "change" }],
  loanType: [{ required: true, message: "请选择贷款类型", trigger: "change" }],
  channelCode: [{ required: true, message: "请选择来源", trigger: "change" }],
  productSn: [{ required: true, message: "请输入产品编号", trigger: "change" }]
};

export { loanTermList, pickerOptions, rules, bankList, tabList };
